
define(['jquery'], () => {
    class RightBorder {
      constructor () {
        this.load().then(() => {
          this.getcarNum()

        })
      }
  

      //获取购物车数量
      getcarNum() {
        var num = 0
        let cartList = localStorage.getItem('cart')
        if(cartList) {
            cartList = JSON.parse(cartList)
            cartList.forEach((item) => {
                num += parseInt(item.num)
            })
        } 
        $('#carNum').html(`${num}`)
        return num 
      }

      // 加载尾部html
      load () {
          return new Promise(resolve => {
            $('.right-border').load('/html/modules/right_border.html',resolve)
          })
          
      }

    }
    return new RightBorder()
  });